package ch.ethz.smseth;

import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;

import org.apache.http.conn.scheme.Scheme;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;

public class TrustServerClient extends DefaultHttpClient {
    public TrustServerClient() {
        super();
        HttpConnectionParams.setConnectionTimeout(this.getParams(), 15000);
    }

    public TrustServerClient(int port, HttpParams params) throws TrustServerException {
    	super(params);
    	try
        {
            registerTrustAllScheme(port);
        }
    	catch (Exception e)
    	{
    		throw new TrustServerException(e);
    	}
    }

    private void registerTrustAllScheme(int port) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException {
        TrustAllSSLSocketFactory tasslf = new TrustAllSSLSocketFactory();
        Scheme sch = new Scheme("https", tasslf, port);
        getConnectionManager().getSchemeRegistry().register(sch);     
    }
     
}
